import Widget from '@/components/application-editor/widget/invisible/DefaultWidget.vue'
import Vue from 'vue'

export interface Prop {
  type: string;
  name: string;
  prop: string;
  value: unknown;
  max?: number;
  min?: number;
  step?: number;
}

export interface PropsGroup {
  type: string;
  name: string;
  prop?: string;
  defaultValue?: boolean;
  propsSchemas: Prop[];
}

export interface WidgetDefinitionOptions {
  /** 组件类的 TAG */
  tag: string;
  /** 组件类的显示名称 */
  displayName: string;
  /** 是组件组 */
  isWidgetGroup?: boolean;
  /** 是内置组件 */
  isBuildin?: boolean;
  /** 是系统组件 */
  isSystem?: boolean;
  /* 自动尺寸 */
  autoSize?: boolean;
  /* 组件的 Vue Component */
  component?: Vue.Component;
  /* 组件的所在的分组 */
  group?: string;
  /* 组件的所在的分组 */
  propsGroups?: PropsGroup[];
}

export default class WidgetDefinition {
  public tag!: string
  public displayName!: string
  public isWidgetGroup!: boolean
  public isBuildin!: boolean
  public isSystem!: boolean
  public autoSize!: boolean
  public group = ''
  public propsGroups: PropsGroup[] = []
  public component: Vue.Component = Widget

  public constructor (options: WidgetDefinitionOptions) {
    this.tag = options.tag
    this.displayName = options.displayName || ''
    this.isWidgetGroup = options.isWidgetGroup || false
    this.component = options.component || Widget
    this.autoSize = options.autoSize || false
    this.isBuildin = options.isBuildin || false
    this.isSystem = options.isSystem || false
    this.group = options.group || ''
    this.propsGroups = options.propsGroups || []
  }
}
